<template>
  <view class="info-card">
    <view class="card-header">
      <view class="header-left">
        <view class="icon-wrapper" v-if="icon">
          <text :class="['iconfont', icon]"></text>
        </view>
        <text class="card-title">{{ title }}</text>
      </view>
      <view class="header-right" v-if="$slots.extra">
        <slot name="extra"></slot>
      </view>
    </view>
    
    <view class="card-content">
      <view v-if="loading" class="loading-container">
        <text class="loading-text">加载中...</text>
      </view>
      
      <view v-else-if="items && items.length > 0" class="info-list">
        <view 
          v-for="(item, index) in items" 
          :key="index"
          class="info-item"
          :class="{ 'item-divider': index < items.length - 1 }"
        >
          <text class="item-label">{{ item.label }}</text>
          <text class="item-value">{{ item.value }}</text>
        </view>
      </view>
      
      <view v-else class="empty-container">
        <text class="empty-text">暂无数据</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'InfoCard',
  props: {
    title: {
      type: String,
      required: true
    },
    icon: {
      type: String,
      default: ''
    },
    items: {
      type: Array,
      default: () => []
    },
    loading: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style lang="scss" scoped>
.info-card {
  background: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
  margin-bottom: 20rpx;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24rpx;
  padding-bottom: 20rpx;
  border-bottom: 2rpx solid #f5f5f5;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.icon-wrapper {
  width: 40rpx;
  height: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8rpx;
}

.iconfont {
  color: #fff;
  font-size: 24rpx;
}

.card-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #333;
}

.header-right {
  display: flex;
  align-items: center;
}

.card-content {
  min-height: 120rpx;
}

.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 120rpx;
}

.loading-text {
  color: #999;
  font-size: 28rpx;
}

.info-list {
  padding: 0;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
}

.item-divider {
  border-bottom: 2rpx solid #f8f8f8;
}

.item-label {
  font-size: 28rpx;
  color: #666;
  flex-shrink: 0;
  margin-right: 20rpx;
}

.item-value {
  font-size: 28rpx;
  color: #333;
  text-align: right;
  flex: 1;
  word-break: break-all;
}

.empty-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 120rpx;
}

.empty-text {
  color: #999;
  font-size: 28rpx;
}

@media (max-width: 750px) {
  .info-card {
    padding: 24rpx;
  }
  
  .card-title {
    font-size: 30rpx;
  }
  
  .item-label,
  .item-value {
    font-size: 26rpx;
  }
}
</style>